package com.qiaofang.applet.service.property.service.dto;

import com.qiaofang.applet.common.util.ImageUtil;
import com.qiaofang.applet.service.property.domain.PropertyExplain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

@Data
@ApiModel("房源列表DTO")
public class PropertyListDto {

    @ApiModelProperty("房源唯一UUID")
    private String propertyUniqueUuid;

    @ApiModelProperty("房源UUID")
    private String propertyUuid;

    @ApiModelProperty("城市code")
    private String cityCode;

    @ApiModelProperty("房源编号")
    private String propertyNo;

    @ApiModelProperty("区域名称")
    private String districtName;

    @ApiModelProperty("商圈名称")
    private String areaName;

    @ApiModelProperty("楼盘名称")
    private String estateName;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("房源主图")
    private String mainImageUrl;

    @ApiModelProperty("户型")
    private String houseType;

    @ApiModelProperty("面积")
    private BigDecimal square;

    @ApiModelProperty("朝向")
    private String direction;

    @ApiModelProperty("房源状态 租/售")
    private String tradeType;

    @ApiModelProperty("建房年代")
    private Integer completeYear;

    @ApiModelProperty("是否有VR")
    private Boolean existVr;

    @ApiModelProperty(value = "房", hidden = true)
    private Integer countF;
    @ApiModelProperty(value = "厅", hidden = true)
    private Integer countT;
    @ApiModelProperty(value = "卫", hidden = true)
    private Integer countW;

    @ApiModelProperty(value = "房源描述集合")
    private List<PropertyExplain> propertyExplainList;

    @ApiModelProperty("房源描述代替列表标题")
    private String propertyDepictTitle;

    public String getMainImageUrl() {
        if (StringUtils.isNotBlank(mainImageUrl)) {
            return mainImageUrl + ImageUtil.getPhotoThumbnail();
        }

        return "";
    }

    /**
     * 1222迭代需求，房源描述存在，取其标题代替房源列表标题
     * @return
     */
    public String getPropertyDepictTitle(){
        if (!CollectionUtils.isEmpty(propertyExplainList)) {
            return propertyDepictTitle = propertyExplainList.get(0).getTitle();
        }
        return propertyDepictTitle;
    }

    public String getTitle() {
        if (StringUtils.isBlank(title)) {
            StringBuffer sb = new StringBuffer();
            sb.append(StringUtils.isNotBlank(getEstateName()) ? getEstateName() : "")
                    .append(" ").append(getHouseType());
            title = sb.toString();
        }
        return title;
    }


    public String getHouseType() {
        StringBuffer sb = new StringBuffer();
        sb.append(getCountF() == null ? "0" : getCountF()).append("室")
                .append((getCountT() == null ? "0" : getCountT()) + "厅")
                .append((getCountW() == null ? "0" : getCountW()) + "卫");

        return sb.toString();
    }
}
